package icu.guodapeng.flutter_plugin_live

import android.content.Context
import android.graphics.Color
import android.util.Log
import android.view.Gravity
import android.view.View
import android.widget.TextView
import io.flutter.plugin.common.BinaryMessenger
import io.flutter.plugin.platform.PlatformView

class FlutterPluginDemoTextView(context: Context, messenger: BinaryMessenger, id: Int?, params: Map<String, Any>?) : PlatformView {
    private val textView: TextView = TextView(context)

    init {
        val text = params?.get("text") as CharSequence?
        textView.text = if (!text.isNullOrEmpty()) {
            text
        } else {
            "android TextView"
        }

        textView.textSize = 30f
        textView.setTextColor(Color.parseColor("#000000"))
        textView.gravity = Gravity.CENTER
        textView.viewTreeObserver.addOnGlobalLayoutListener {
            Log.e("flutter_plugin_live", "parent:" + textView.parent.javaClass.name)
        }
    }

    override fun getView(): View = textView
    override fun dispose() {
    }
}